package genericity_learn

/*
泛型
*/

func Print[T any](s []T) {
	for _, item := range s {
		println(item)
	}
}

type Stack[T any] struct {
	List []T
}

func (s *Stack[T]) Push(v T) {
	s.List = append(s.List, v)
}

func Equal[T comparable](a, b T) bool {
	if a == b {
		return true
	}
	return false
}

func InArray[T comparable](v T, s []T) bool {
	for _, item := range s {
		if item == v {
			return true
		}
	}
	return false
}

func Sum1[T int | uint | int8 | uint8](a, b T) T {
	return a + b
}

type number1 interface {
	int | int8 | int16 | int32 | int64
}

type number2 interface {
	uint | uint8 | uint16 | uint32 | uint64
}

func Sum2[T number1](a, b T) T {
	return a + b
}

func Sum3[T number2](a, b T) T {
	return a + b
}

type number3 interface {
	number1 | number2
}

func Sum4[T number3](a, b T) T {
	return a + b
}
